package com.airnewslinkosky.ticket.sql;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class PassengerDB {
	private static final String PASSENGER_TABLE_NAME = "passengers";

	public static void insert(Context context, ContentValues values) {
		DBHelper mOpenHelper = new DBHelper(context);
		long id = mOpenHelper.getReadableDatabase().insert(PASSENGER_TABLE_NAME,
				"id", values);
		mOpenHelper.getReadableDatabase().close();
	}

	public static void delete(Context context, String orderId) {
		DBHelper mOpenHelper = new DBHelper(context);
		String[] param = new String[] {orderId };
		mOpenHelper.getWritableDatabase().delete(PASSENGER_TABLE_NAME, "orderId=?",
				param);
		mOpenHelper.getWritableDatabase().close();
	}
	
	public static List<Map<String, String>> select(Context context,
			String orderId) {
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		DBHelper mOpenHelper = new DBHelper(context);
		String[] columns = new String[] { "id", "orderId", "pname",
				"paperType", "paperNum", "assu" };
		Cursor c = mOpenHelper.getReadableDatabase().query(PASSENGER_TABLE_NAME,
				columns, "orderId=?", new String[] { orderId }, null, null, null);
		c.moveToFirst();
		for (int i = 0; i < c.getCount(); i++) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("id", String.valueOf(c.getInt(0)));
			map.put("orderId", c.getString(1));
			map.put("pname", c.getString(2));			
			map.put("paperType", c.getString(3));
			map.put("paperNum", c.getString(4));
			map.put("assu", c.getString(5));
			data.add(map);
			c.moveToNext();
		}
		c.close();
		mOpenHelper.getReadableDatabase().close();
		return data;
	}
}
